$(function () {
    layui.use(['form', 'layer'], function (obj) {
        $('#emailRegPre').on('click', function (obj) {
            layer.open({
                type: 1,
                title: '邮箱注册',
                shade: 0,
                content: '<div class="layui-col-md10"><form class="layui-form" style="padding-top: 20px">' +
                ' <div class="layui-form-item">' +
                '<label class="layui-form-label">客户昵称</label>' +
                '<div class="layui-input-block">' +
                ' <input type="text" name="cuid" required  lay-verify="required" placeholder="请输入客户昵称" autocomplete="off" class="layui-input">' +
                '</div>' +
                '</div>' +

                ' <div class="layui-form-item">' +
                '<label class="layui-form-label">企业名称</label>' +
                '<div class="layui-input-block">' +
                '<input type="text" name="title" required  lay-verify="required" placeholder="请输入企业名称" autocomplete="off" class="layui-input">' +
                '</div>' +
                '</div>' +
                ' <div class="layui-form-item">' +
                '<label class="layui-form-label">真实姓名</label>' +
                '<div class="layui-input-block">' +
                '<input type="text" name="name" required  lay-verify="required" placeholder="请输入真实姓名" autocomplete="off" class="layui-input">' +
                '</div>' +
                '</div>' +
                ' <div class="layui-form-item">' +
                '<label class="layui-form-label">联系邮箱</label>' +
                '<div class="layui-input-block">' +
                '<input type="text" name="email" required  lay-verify="required|mail" placeholder="请输入登录密码" autocomplete="off" class="layui-input">' +
                '</div>' +
                '</div>' +

                ' <div class="layui-form-item">' +
                '<label class="layui-form-label">联系电话</label>' +
                '<div class="layui-input-block">' +
                '<input type="text" name="phone" required  lay-verify="required|phone" placeholder="请输入系电话" autocomplete="off" class="layui-input">' +
                '</div>' +
                '</div>' +
                ' <div class="layui-form-item">' +
                '<label class="layui-form-label">登录密码</label>' +
                '<div class="layui-input-block">' +
                '<input type="password" name="password" required  lay-verify="required" placeholder="请输入登录密码" autocomplete="off" class="layui-input">' +
                '</div>' +
                '</div>' +
                ' <div class="layui-form-item">' +
                '<div class="layui-input-block">' +
                '<input type="button" class="layui-btn layui-btn-normal layui-btn-sm layui-col-md-offset2"' +
                'lay-submit lay-filter="formDemo" id="regBtn" value="注册">' +
                '<button type="reset" class="layui-btn layui-btn-danger layui-btn-sm">重置</button>' +
                '</div>' +
                '</div>' +
                '</form></div><div class="layui-col-md2">&nbsp;</div>'
            })
            $(function () {
                $("#regBtn").on('click',function () {
                    $.ajax({
                        url:'/email',
                        type: 'POST',
                        resultType:"JSON",
                        data: $('.layui-form').serialize(),
                        success:function (data) {
                            // alert(data.code)
                            if(data.code == 200){ // 表示成功
                                layer.msg('注册成功',{time:1000,icon:1,end:function () {
                                        // 登录成功之后跳转到后台首页
                                        window.location.href = "/";
                                    }})
                            } else if(data.code == 400){
                                layer.msg('注册失败,该邮箱已被注册',{time:1000,icon:2})
                            }
                        }
                    })
                })
            })
        })
    })
})